package sample.stormax.pres.news.fragments;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import sample.stormax.pres.news.R;
import sample.stormax.pres.news.adapters.NewsAdapter;
import sample.stormax.pres.news.utils.sqlite.FavouriteSQLiteImpl;
import sample.stormax.pres.news.utils.sqlite.ISQLiteOperation;

public class FavouriteFragment extends Fragment {

    private static FavouriteFragment favouriteFragment;
    private View view;

    private RecyclerView recyclerView;
    private NewsAdapter adapter;

    public FavouriteFragment() {
    }

    public static FavouriteFragment newInstance() {
        favouriteFragment = favouriteFragment == null ? new FavouriteFragment() : favouriteFragment;
        return favouriteFragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (view == null) {
            view = inflater.inflate(R.layout.list_news, container, false);
            recyclerView = (RecyclerView) view;
            recyclerView.setLayoutManager(new LinearLayoutManager(view.getContext()));
            recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
            initAdapter();
        }

        return view;
    }


    public void setAdapter(NewsAdapter adapter) {
        this.adapter = adapter;
    }

    private void initAdapter(){
        recyclerView.setAdapter(adapter);
    }
}
